Skip to main content

winsafe\comctl\messages/
pbm.rs

1use crate::co;
2use crate::comctl::privs::*;
3use crate::decl::*;
4use crate::msg::*;
5use crate::prelude::*;
6use crate::user::privs::*;
7
8/// [`PBM_DELTAPOS`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-deltapos)
9/// message parameters.
10///
11/// Return type: `u32`.
12pub struct PbmDeltaPos {
13	pub advance_amount: u32,
14}
15
16impl MsgSend for PbmDeltaPos {
17	type RetType = u32;
18
19	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
20		v as _
21	}
22
23	fn as_generic_wm(&mut self) -> Wm {
24		Wm {
25			msg_id: co::PBM::DELTAPOS.into(),
26			wparam: self.advance_amount as _,
27			lparam: 0,
28		}
29	}
30}
31
32/// [`PBM_GETBARCOLOR`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getbarcolor)
33/// message, which has no parameters.
34///
35/// Return type: `Option<COLORREF>`.
36pub struct PbmGetBarColor {}
37
38impl MsgSend for PbmGetBarColor {
39	type RetType = Option<COLORREF>;
40
41	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
42		match v as u32 {
43			CLR_DEFAULT => None,
44			v => Some(unsafe { COLORREF::from_raw(v) }),
45		}
46	}
47
48	fn as_generic_wm(&mut self) -> Wm {
49		Wm {
50			msg_id: co::PBM::GETBARCOLOR.into(),
51			wparam: 0,
52			lparam: 0,
53		}
54	}
55}
56
57/// [`PBM_GETBKCOLOR`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getbkcolor)
58/// message, which has no parameters.
59///
60/// Return type: `Option<COLORREF>`.
61pub struct PbmGetBkColor {}
62
63impl MsgSend for PbmGetBkColor {
64	type RetType = Option<COLORREF>;
65
66	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
67		match v as u32 {
68			CLR_DEFAULT => None,
69			v => Some(unsafe { COLORREF::from_raw(v) }),
70		}
71	}
72
73	fn as_generic_wm(&mut self) -> Wm {
74		Wm {
75			msg_id: co::PBM::GETBKCOLOR.into(),
76			wparam: 0,
77			lparam: 0,
78		}
79	}
80}
81
82/// [`PBM_GETPOS`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getpos)
83/// message, which has no parameters.
84///
85/// Return type: `u32`.
86pub struct PbmGetPos {}
87
88impl MsgSend for PbmGetPos {
89	type RetType = u32;
90
91	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
92		v as _
93	}
94
95	fn as_generic_wm(&mut self) -> Wm {
96		Wm {
97			msg_id: co::PBM::GETPOS.into(),
98			wparam: 0,
99			lparam: 0,
100		}
101	}
102}
103
104/// [`PBM_GETRANGE`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getrange)
105/// message parameters.
106///
107/// Return type: `i32`.
108pub struct PbmGetRange<'a> {
109	pub return_low: bool,
110	pub ranges: Option<&'a mut PBRANGE>,
111}
112
113impl<'a> MsgSend for PbmGetRange<'a> {
114	type RetType = i32;
115
116	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
117		v as _
118	}
119
120	fn as_generic_wm(&mut self) -> Wm {
121		Wm {
122			msg_id: co::PBM::GETRANGE.into(),
123			wparam: self.return_low as _,
124			lparam: self.ranges.as_mut().map_or(0, |r| r as *mut _ as _),
125		}
126	}
127}
128
129/// [`PBM_GETSTATE`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getstate)
130/// message, which has no parameters.
131///
132/// Return type: `co::PBST`.
133pub struct PbmGetState {}
134
135impl MsgSend for PbmGetState {
136	type RetType = co::PBST;
137
138	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
139		unsafe { co::PBST::from_raw(v as _) }
140	}
141
142	fn as_generic_wm(&mut self) -> Wm {
143		Wm {
144			msg_id: co::PBM::GETSTATE.into(),
145			wparam: 0,
146			lparam: 0,
147		}
148	}
149}
150
151/// [`PBM_GETSTEP`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-getstep)
152/// message, which has no parameters.
153///
154/// Return type: `u32`.
155pub struct PbmGetStep {}
156
157impl MsgSend for PbmGetStep {
158	type RetType = u32;
159
160	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
161		v as _
162	}
163
164	fn as_generic_wm(&mut self) -> Wm {
165		Wm {
166			msg_id: co::PBM::SETSTEP.into(),
167			wparam: 0,
168			lparam: 0,
169		}
170	}
171}
172
173/// [`PBM_SETBARCOLOR`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setbarcolor)
174/// message parameters.
175///
176/// Return type: `Option<COLORREF>`.
177pub struct PbmSetBarColor {
178	pub color: Option<COLORREF>,
179}
180
181impl MsgSend for PbmSetBarColor {
182	type RetType = Option<COLORREF>;
183
184	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
185		match v as u32 {
186			CLR_DEFAULT => None,
187			v => Some(unsafe { COLORREF::from_raw(v) }),
188		}
189	}
190
191	fn as_generic_wm(&mut self) -> Wm {
192		Wm {
193			msg_id: co::PBM::SETBARCOLOR.into(),
194			wparam: self.color.map_or(CLR_DEFAULT, |color| color.into()) as _,
195			lparam: 0,
196		}
197	}
198}
199
200/// [`PBM_SETBKCOLOR`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setbkcolor)
201/// message parameters.
202///
203/// Return type: `Option<COLORREF>`.
204pub struct PbmSetBkColor {
205	pub color: Option<COLORREF>,
206}
207
208impl MsgSend for PbmSetBkColor {
209	type RetType = Option<COLORREF>;
210
211	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
212		match v as u32 {
213			CLR_DEFAULT => None,
214			v => Some(unsafe { COLORREF::from_raw(v) }),
215		}
216	}
217
218	fn as_generic_wm(&mut self) -> Wm {
219		Wm {
220			msg_id: co::PBM::SETBKCOLOR.into(),
221			wparam: self.color.map_or(CLR_DEFAULT, |color| color.into()) as _,
222			lparam: 0,
223		}
224	}
225}
226
227/// [`PBM_SETMARQUEE`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setmarquee)
228/// message parameters.
229///
230/// Return type: `()`.
231pub struct PbmSetMarquee {
232	pub turn_on: bool,
233	pub time_ms: Option<u32>,
234}
235
236impl MsgSend for PbmSetMarquee {
237	type RetType = ();
238
239	unsafe fn isize_to_ret(&self, _: isize) -> Self::RetType {
240		()
241	}
242
243	fn as_generic_wm(&mut self) -> Wm {
244		Wm {
245			msg_id: co::PBM::SETMARQUEE.into(),
246			wparam: self.turn_on as _,
247			lparam: self.time_ms.unwrap_or(0) as _,
248		}
249	}
250}
251
252/// [`PBM_SETPOS`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setpos)
253/// message parameters.
254///
255/// Return type: `u32`.
256pub struct PbmSetPos {
257	pub position: u32,
258}
259
260impl MsgSend for PbmSetPos {
261	type RetType = u32;
262
263	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
264		v as _
265	}
266
267	fn as_generic_wm(&mut self) -> Wm {
268		Wm {
269			msg_id: co::PBM::SETPOS.into(),
270			wparam: self.position as _,
271			lparam: 0,
272		}
273	}
274}
275
276/// [`PBM_SETRANGE`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setrange)
277/// message parameters.
278///
279/// Return type: `SysResult<(u16, u16)>`.
280pub struct PbmSetRange {
281	pub min: u16,
282	pub max: u16,
283}
284
285impl MsgSend for PbmSetRange {
286	type RetType = SysResult<(u16, u16)>;
287
288	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
289		zero_as_badargs(v).map(|v| (LOWORD(v as _), HIWORD(v as _)))
290	}
291
292	fn as_generic_wm(&mut self) -> Wm {
293		Wm {
294			msg_id: co::PBM::SETRANGE.into(),
295			wparam: 0,
296			lparam: MAKEDWORD(self.min, self.max) as _,
297		}
298	}
299}
300
301/// [`PBM_SETRANGE32`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setrange32)
302/// message parameters.
303///
304/// Return type: `()`.
305pub struct PbmSetRange32 {
306	pub min: u32,
307	pub max: u32,
308}
309
310impl MsgSend for PbmSetRange32 {
311	type RetType = ();
312
313	unsafe fn isize_to_ret(&self, _: isize) -> Self::RetType {
314		()
315	}
316
317	fn as_generic_wm(&mut self) -> Wm {
318		Wm {
319			msg_id: co::PBM::SETRANGE32.into(),
320			wparam: self.min as _,
321			lparam: self.max as _,
322		}
323	}
324}
325
326/// [`PBM_SETSTATE`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setstate)
327/// message parameters.
328///
329/// Return type: `co::PBST`.
330pub struct PbmSetState {
331	pub state: co::PBST,
332}
333
334impl MsgSend for PbmSetState {
335	type RetType = co::PBST;
336
337	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
338		unsafe { co::PBST::from_raw(v as _) }
339	}
340
341	fn as_generic_wm(&mut self) -> Wm {
342		Wm {
343			msg_id: co::PBM::SETSTATE.into(),
344			wparam: self.state.raw() as _,
345			lparam: 0,
346		}
347	}
348}
349
350/// [`PBM_SETSTEP`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-setstep)
351/// message parameters.
352///
353/// Return type: `u32`.
354pub struct PbmSetStep {
355	pub step: u32,
356}
357
358impl MsgSend for PbmSetStep {
359	type RetType = u32;
360
361	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
362		v as _
363	}
364
365	fn as_generic_wm(&mut self) -> Wm {
366		Wm {
367			msg_id: co::PBM::SETSTEP.into(),
368			wparam: self.step as _,
369			lparam: 0,
370		}
371	}
372}
373
374/// [`PBM_STEPIT`](https://learn.microsoft.com/en-us/windows/win32/controls/pbm-stepit)
375/// message, which has no parameters.
376///
377/// Return type: `u32`.
378pub struct PbmStepIt {}
379
380impl MsgSend for PbmStepIt {
381	type RetType = u32;
382
383	unsafe fn isize_to_ret(&self, v: isize) -> Self::RetType {
384		v as _
385	}
386
387	fn as_generic_wm(&mut self) -> Wm {
388		Wm {
389			msg_id: co::PBM::STEPIT.into(),
390			wparam: 0,
391			lparam: 0,
392		}
393	}
394}